package com.fuyun.rpc.dto;

import com.fuyun.rpc.enums.RpcRespStatus;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @Author fuyun。
 * @Date 2025/8/21 15:54。
 * @Description: TODO。
 **/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RpcResp<T> implements Serializable {

    private String requestId;
    private Integer code;
    private String msg;
    private T data;


    public static <T> RpcResp<T> success(String requestId, T data) {
        RpcResp<T> resp = new RpcResp<>();
        resp.setRequestId(requestId);
        resp.setCode(RpcRespStatus.SUCCESS.getCode());
        resp.setMsg(RpcRespStatus.SUCCESS.getMsg());
        resp.setData(data);
        return resp;
    }

    public static <T> RpcResp<T> fail(String requestId, String msg) {
        RpcResp<T> resp = new RpcResp<>();
        resp.setRequestId(requestId);
        resp.setCode(RpcRespStatus.FAILED.getCode());
        resp.setMsg(msg);
        return resp;
    }

}
